<!-- 报表标题组件 -->

<template>
    <div class="reportTitle">
        <div class="left">
            <span class="divide"></span>
            <span class="title">{{ titleInfo.title }}</span>
            <template v-if="titleInfo.description">
                <el-popover placement="right" width="600" trigger="hover" popper-class="description-popper">
                    <template #reference>
                        <el-icon>
                            <InfoFilled />
                        </el-icon>
                    </template>
                    <div class="popoverContainer">
                        <span class="startText">说明: </span>
                        <div class="formulaContents">
                            <span v-for="item, index in formulaDatas" :key="index" class="item">
                                <span class="dotBox">
                                    <span class="dot"></span>
                                </span>
                                <span>{{ item }}</span>
                            </span>
                        </div>
                    </div>
                </el-popover>
            </template>
        </div>
        <div class="right">
            <div class="exportBtn" @click="exportFile" v-show="isExport">
                <i class="iconfont icon-daochu icon"></i>
                <span class="text">导出</span>
            </div>
            <div class="exportBtn" @click="add" v-show="isAdd">
                <i class="iconfont icon-xinjian icon"></i>
                <span class="text">新增</span>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';

const props = defineProps({
    titleInfo: {
        type: Object,
        default: () => { }
    },
    isExport: {
        type: Boolean,
        default: true
    },
    isAdd: {
        type: Boolean,
        default: false
    }
});

const emit = defineEmits(['handleExport', 'handleAdd']);

const formulaDatas = ref('');

onMounted(() => {
    const description = props.titleInfo?.description;
    if(description){
        formulaDatas.value = description.split(';');
    }
});

const exportFile = () => {
    emit('handleExport');
};

const add = () => {
    emit('handleAdd');
};
</script>

<style lang="scss" scoped>
@import "./index.scss";
</style>